package com.dang.alex.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Servlet implementation class ValDateCheckCodeServlet
 */
@WebServlet("/ValDateCheckCodeServlet.do")
public class ValDateCheckCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private boolean flag=false; 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String checkcode=request.getParameter("chcode");
		String sessioncheckcode=(String)request.getSession().getAttribute("checkcode");
		if(checkcode!=null&&checkcode.equalsIgnoreCase(sessioncheckcode)) {
			flag=true;
		}else {
			flag=false;
		}
		JSONObject json=new JSONObject();
		try {
			json.put("flag", flag);
			PrintWriter out=response.getWriter();
			out.println(json.toString());
			out.close();
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

}
